package models

import (
	"time"

	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// MaterialTheme 素材主题
type MaterialTheme struct {
	ID                string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键id"`
	MerchantID        string `json:"merchant_id" gorm:"column:merchant_id;type:int;size:64;index:merchant_id;default:0;comment:所属商户"`
	Name              string `json:"name" gorm:"column:name;index:name;type:string;size:40;comment:名称"`
	SoundSource       string `json:"sound_source" gorm:"column:sound_source;type:string;size:40;not null;default:'';comment:音源"`
	IsDefault         int    `json:"is_default" gorm:"column:is_default;type:int;size:8;default:0;comment:是否默认身份,0否1是"`
	PersonalityPrompt string `json:"personality_prompt" gorm:"column:personality_prompt;type:text;not null;comment:人格提示词"`
	Permanent         int    `json:"permanent" gorm:"column:permanent;type:int;size:8;default:0;comment:是否永久,0否1是"`
	StartTime         int64  `json:"start_time" gorm:"column:start_time;type:int;size:64;comment:开始时间"`
	EndTime           int64  `json:"end_time" gorm:"column:end_time;type:int;size:64;comment:结束时间"`
	CreatedUser       string `json:"created_user" gorm:"column:created_user;type:string;size:20;comment:操作人"`
	CreatedAt         int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间"`
	UpdatedAt         int64  `json:"updated_at" gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间"`
	DeletedAt         int64  `json:"-" gorm:"column:deleted_at;index:deleted_at;type:int;size:64;comment:删除时间"`
}

// TableName 表名
func (MaterialTheme) TableName() string {
	return "material_theme_v2"
}

// BeforeCreate
func (l *MaterialTheme) BeforeCreate(tx *gorm.DB) (err error) {
	// id为空时，自动添加id
	if l.ID != "" {
		return nil
	}
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	l.UpdatedAt = time.Now().Unix()
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &MaterialTheme{})
}
